var util = require('../utils/util.js')


function getNewApp() {
	const oldApp = App;

	return (args) => {
		const { onLaunch, onShow, onHide, onError, onPageNotFound } = args;

    // 重写onLaunch
    args.onLaunch = function(opt) {
      // 自定义行为

      util.pushLog({
      	page: opt.path,
      	name: 'app-launch'
      });

      if (onLaunch) {
      	return onLaunch.call(this, opt);
      }
  };

    // 重写onShow
    args.onShow = function(opt) {
      // 自定义行为

      util.pushLog({
      	page: opt.path,
      	name: 'app-show'
      });

      if (onShow) {
      	return onShow.call(this, opt);
      }
  };

    // 重写onHide
    args.onHide = function(opt) {
      // 自定义行为

      util.pushLog({
      	page: opt.path,
      	name: 'app-hide'
      });

      if (onHide) {
      	return onHide.call(this, opt);
      }
  };

    // 重写onError
    args.onError = function(opt) {
      // 自定义行为

      util.pushLog({
      	page: opt.path,
      	name: 'app-error'
      });

      if (onError) {
      	return onError.call(this, opt);
      }
  };

    // 重写onPageNotFound
    args.onPageNotFound = function(opt) {
      // 自定义行为

      util.pushLog({
      	page: opt.path,
      	name: 'app-page-not-found'
      });

      if (onPageNotFound) {
      	return onPageNotFound.call(this, opt);
      }
  };

  return oldApp.call(this, args);
};
}

App = getNewApp();
